<title>利润计算</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>销售管理</cite></a>
        <a><cite>扣款汇总</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="app-content-list">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">店铺名称</label>
                    <div class="layui-input-inline">
                        <select name="mallId" id="app-mall-list" lay-filter="app-mall-filter">
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">请选择范围</label>
                    <div class="layui-input-inline">
                        <input name="dataTime" type="text" class="layui-input" id="temu-laydate-deduct" lay-filter="temu-laydate-deduct"
                               placeholder="开始 到 结束">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">扣款名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="remark" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-temu-deduct-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="LAY-temu-deduct-list" lay-filter="LAY-temu-deduct-list">
            </table>
        </div>
    </div>
</div>
<script>
    function firstDayOfMonth() {
        const currentDate = new Date();
        const year = currentDate.getFullYear();//获取当前年
        const month = String(currentDate.getMonth() + 1).padStart(2, "0");//获取当前月
        const firstDay = "01";//日
        return `${year}-${month}-${firstDay} 00:00:00`;
    }

    function currentTime() {
        var currentDate = new Date();
        var year = currentDate.getFullYear();
        var month = currentDate.getMonth() + 1; // 月份从0开始计数，所以需要加1
        var day = currentDate.getDate();
        var hour = currentDate.getHours();
        var minute = currentDate.getMinutes();
        var second = currentDate.getSeconds();
        var currentDateTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
        return currentDateTime;
    }

    layui.use('deduct', layui.factory('deduct')).use(['admin', 'laydate', 'table'], function () {
        var $ = layui.$
            , admin = layui.admin
            , table = layui.table
            , form = layui.form
            , laydate = layui.laydate
            , setter = layui.setter
            , request = layui.request;
        laydate.render({
            elem: '#temu-laydate-deduct',
            value: firstDayOfMonth() + " ~ " + currentTime(),
            type: 'datetime',
            range: '~',
            format: 'yyyy-MM-dd HH:mm:ss'
        });
        admin.req({
            url: '/temu/queryMallList',
            type: 'post',
            done: function (data) {
                $.each(data.data, function (index, item) {
                    $('#app-mall-list').append(new Option(item.mallName, item.mallId));// 下拉菜单里添加元素
                });
                form.render(null, 'app-content-list');

                table.render({
                    elem: '#LAY-temu-deduct-list'
                    , url: '/temu/queryDeductList'
                    , headers: {'access_token': layui.data(setter.tableName)[setter.request.tokenName]}
                    , where: {mallId: $("#app-mall-list option:selected").val(),dataTime:$("#temu-laydate-deduct").val()}
                    , method: 'post'
                    , height: 'full-250'
                    , cols: [[
                        {field: 'transactionTime', title: '账务时间', totalRow: '合计'}
                        // , {field: 'symbol', title: '币种',width:70}
                        , {
                            field: 'digitalText',
                            title: '扣款金额',
                            totalRow: function (d) {
                                return d.digitalText
                            },
                            templet: function (d) {
                                return d.digitalText
                            }
                        }
                        , {field: 'remark', title: '扣款名称'}
                    ]]
                    , totalRow: true
                    , text: {none:'暂无数据'}
                });
            }
        });


        // form.render('select', 'app-content-list');
        //搜索

        form.on('submit(LAY-temu-deduct-search)', function (data) {
            var field = data.field;
            console.log(field);
            //执行重载
            table.reload('LAY-temu-deduct-list', {
                where: field
            });
        });
        form.on('select(app-mall-filter)', function (data) {
            table.reload('LAY-temu-deduct-list', {
                where: {mallId: data.value}
            });
        });


    });
</script>
